home *** CD-ROM | disk | FTP | other *** search
Wrap
if (!topsite) var topsite = {}; if (!topsite.consts) topsite.consts = {}; if (!topsite.common) topsite.common = {}; topsite.consts = { IS_DEBUG_MODE: false, STRING_BUNDLE: Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService) .createBundle("chrome://topsite/locale/topsite.properties"), URL_MAIN_LB: "http://similarnet.com/LoadBalancer/Main.asmx", URL_MAIN_LB_BAK: "http://similarweb.net/LoadBalancer/Main.asmx", DATA_WS_NS: "http://schemas.datacontract.org/2004/07/SimilarService", XHTML_NS: "http://www.w3.org/1999/xhtml", XUL_NS: "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", // Site status STATUS_OK : "0", STATUS_SOON : "1", STATUS_NOT_SOON : "2", STATUS_INVALID : "3", STATUS_NO_DATA : "4", // Navigation types NAV_TYPE_REGULAR : "500", NAV_TYPE_CLICKED : "511", NAV_TYPE_ADV : "512", // Client cache modes CACHE_NONE : "0", // No cache CACHE_IMAGE_ONLY : "1", // Cache images only CACHE_PARTIAL : "2", // Partial cache, full cache (save related sites and images, all data) - BUT still call server, only one way (for statistics) CACHE_FULL : "4", // Full Cache - no calls to the server at all if the data is in the cache CACHE_ON_DEMAND : "5", // Full Cache - no calls to the server at all if the data is in the cache, and when in button mode - call to the server only on drop down HTTP_STATUS_OK : 200, HTTP_STATUS_ACCEPTED : 202, // Preferences: // Second load balancer url PREF_SECOND_LB : "extensions.topsite.secondLbURL", PREF_G_SESSION : "extensions.topsite.gSession" }; topsite.common = { prefManager: Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch), extMan: Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager), getAddonVersion: function(){ var item = topsite.common.extMan.getItemForID("FirefoxAddon@topsite.com"); return "TS:" + item.version; }, S4: function() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); }, guid: function() { with(topsite.common){ return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()); } }, m_strGSessionId: null, getGSessionId: function(){ if (topsite.common.m_strGSessionId == null){ try{ topsite.common.m_strGSessionId = this.prefManager.getCharPref(topsite.consts.PREF_G_SESSION); }catch(e){} if (!topsite.common.m_strGSessionId){ topsite.common.m_strGSessionId = topsite.common.guid(); topsite.common.prefManager.setCharPref(topsite.consts.PREF_G_SESSION, topsite.common.m_strGSessionId); } } return topsite.common.m_strGSessionId; }, debug: function(msg, isFull){ if (!topsite.consts.IS_DEBUG_MODE) return; var date = new Date(); var timeStr = date.getMinutes() + ":" + date.getSeconds() + ":" + date.getMilliseconds(); var prefix = "TS (" + timeStr + ") "; try { a.b = b.c; } catch (e) { if (isFull) { dump(prefix + ": " + e.stack + "\n"); return; } var s = "chrome://topsite/content/"; var index = e.stack.indexOf(s); index = e.stack.indexOf(s, index+1); var index2 = e.stack.indexOf("\n", index+1); var lineNumber = e.stack.substring(index+s.length, index2); dump(prefix + lineNumber + ": " + msg + "\n"); // output to error console window.setTimeout(function() { throw new Error("[debug] " + msg); }, 0); } }, keyHandler: function(event) { if (event.keyCode==event.DOM_VK_RETURN) topsite.overlay.findTopSite(); }, openUrlFromDialog: function(url) { var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator); var win = wm.getMostRecentWindow("navigator:browser"); var gBrowser = win.getBrowser(); gBrowser.loadOneTab(url, null, null, null, false, false); }, trim: function(str){ return str.replace(/^\s*/, "").replace(/\s*$/, ""); }, capitalizeWords: function(string){ var words = string.split(" "); string = ""; for each(word in words) { string = string + " " + word.substring(0, 1).toUpperCase() + word.substring(1, word.length); } return string.replace(/^\s+|\s+$/g,""); } };